﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.lishun;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain;
using SheepStorage.Domain.DTO.Output;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.SheepRecordHandlers
{
    /// <summary>
    /// 羊只档案查询显示
    /// </summary>
    public class SheepRecordCommandHandler : IRequestHandler<SheepRecordCommand, Results<List<SheepRecordOutput>>>
    {
        ISheepRecordService _service;
        IMapper _mapper;
        public SheepRecordCommandHandler(ISheepRecordService service, IMapper mapper)
        {
            _service = service;
            _mapper = mapper;
        }


        public async Task<Results<List<SheepRecordOutput>>> Handle(SheepRecordCommand request, CancellationToken cancellationToken)
        {
            int totalCount;
            int pageCount;
            var list = _mapper.Map<List<SheepRecordOutput>>(_service.GetSheepRecord(request.sheepRecordInput));

            return await Task.FromResult(Results<List<SheepRecordOutput>>.DataResult(list));
        }
    }
}
